home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Browsers, Managers & Extensions
/
Firefox Backup Extension 6.0.3
/
chrome
/
febe.jar
/
content
/
febe.js
< prev
next >
Wrap
Text File
|
2008-09-21
|
80KB
|
2,371 lines
// author: Chuck Baker
// contact: febe@customsoftwareconsult.com
// Version 6.0
window.addEventListener("load",febeLoad,true);
function febeLoad(){
febeSetMsgs();
// See if this is a new update/install
var version = getFebeVersion();
var newFEBEinstall = new Boolean(false);
var prefName = "extensions.febe.previousversion";
if(febePrefs.prefHasUserValue(prefName)){
var pversion = febePrefs.getCharPref(prefName);
if (pversion != version){newFEBEinstall = true;}
}else{
newFEBEinstall = true;
}//if
febePrefs.setCharPref(prefName,version);
if(newFEBEinstall == true){
// Get a list on installed locales
var locales = febeLocales();
var locale = febePrefs.getCharPref("general.useragent.locale");
if(locale.length == 2){ // If the locale is only two characters, just guess what it's supposed to be
switch(locale){
case "en":
locale = "en-US";
break;
case "fr":
locale = "fr-FR";
break;
case "es":
locale = "es-ES";
break;
case "pl":
locale = "pl-PL";
break;
case "nl":
locale = "nl-NL";
break;
case "zh":
locale = "zh-CN";
break;
case "de":
locale = "de-DE";
break;
case "ja":
locale = "ja-JP";
break;
case "it":
locale = "it-IT";
break;
case "pt":
locale = "pt-BR";
break;
case "sv":
locale = "sv-SE";
break;
case "sk":
locale = "sk-SK";
break;
case "ru":
locale = "ru-RU";
break;
default:
locale = "en-US";
break;
}//switch
}//if
if(locales.indexOf(locale) == -1){locale = "en-US";}
febeWelcomePage = "http://customsoftwareconsult.com/extensions/febe/locale/"+locale+"/FEBEwelcome["+locale+"].html";
setTimeout("febeWelcomePageDisplay()",1500); // Let the browser catch up
}//if
setTimeout('febeRemind()',3000); // Remind after Fx boots
if(!febeScheduledBuTimer){
febeScheduledBuTimer = Cc['@mozilla.org/timer;1'].createInstance(Ci.nsITimer);
}
febeScheduleBackup();
window.removeEventListener("load",febeLoad,true);
return true;
}//febeLoad()
function febeLocales(){
// Return a list of installed locales
// Parse chrome.manifest
// ex:
// locale febe en-US jar:chrome/febe.jar!/locale/en-US/
// locale febe bg-BG jar:chrome/febe.jar!/locale/bg-BG/
// locale febe da-DK jar:chrome/febe.jar!/locale/da-DK/
var extDir = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("ProfD", Ci.nsIFile);
extDir.append("extensions");
extDir.append(FEBE_GUID);
extDir.append("chrome.manifest");
// open an input stream from file
var istream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
istream.init(extDir, 0x01, 0444, 0);
istream.QueryInterface(Ci.nsILineInputStream);
// read lines into array
var lArray = [];
var line = {}, hasmore;
var str = "jar:chrome/febe.jar!/locale/";
do {
hasmore = istream.readLine(line); // locale febe en-US jar:chrome/febe.jar!/locale/en-US/
var idx = line.value.indexOf(str);
if(idx != -1){
var tmp = line.value.substring(idx); // jar:chrome/febe.jar!/locale/en-US/
tmp = tmp.substring(str.length); // en-US/
idx = tmp.indexOf("/");
tmp = tmp.substring(0,idx); // en-US
lArray.push(tmp);
}//if
} while(hasmore);
istream.close();
return lArray;
}//febeLocales()
function febeWelcomePageDisplay(){
gBrowser.selectedTab = gBrowser.addTab(febeWelcomePage);
}//febeWelcomePage()
function febeRemind(){
// See if we need to remind about a backup
if(febeReminded == true){return true;}
var prefName = "extensions.febe.lastbackup";
if(!febePrefs.prefHasUserValue(prefName)){return true;}
var lastBU = Date.parse(febePrefs.getCharPref(prefName));
var now = Date.parse(Date());
var reminderDays = febePrefs.getIntPref("extensions.febe.reminderdays");
if(reminderDays > 0){
var elapsed = (now - lastBU) / (24 * 60 * 60 * 1000); // Number of days since last backup
if(elapsed >= reminderDays){
var tmp = "<style>color: red; font-weight: bold; font-size: 20px;</style>"+febeMsg[171]+"\n";
tmp += "<style>color: black;</style>"+febeMsg[172].replace("%days%",parseInt(elapsed))+"\n";
tmp += febeLocalizedDate(lastBU)+"\n\n";
tmp += "<style>color: black;</style>"+febeMsg[232]+"\n";
tmp += "<style>color: black; font-weight: bold; font-size: 15px;</style>"+febeMsg[233]+"\n";
if(febeConfirm(tmp)){febeInit();}
febeReminded = true;
}//if
}
if(febePrefs.getCharPref("extensions.febe.schedule.frequency") == "none") return;
var nextBU = Date.parse(febePrefs.getCharPref("extensions.febe.schedule.description"));
if(nextBU < lastBU){
var tmp = "<style>color: red; font-weight: bold; font-size: 20px;</style>"+febeMsg[234]+"\n";
tmp += "<style>color: black;</style>"+febeMsg[235]+"\n";
tmp += febeLocalizedDate(nextBU)+"\n";
tmp += "<style>color: black;</style>"+febeMsg[236]+"\n";
tmp += "<style>color: black; font-weight: bold; font-size: 15px;</style>"+febeMsg[233]+"\n";
if(febeConfirm(tmp)){febeInit();}
febeReminded = true;
}//if
return true;
}//febeRemind()
function febeGetEnvironmentVariableValue(envString){
var env = Cc["@mozilla.org/process/environment;1"].createInstance(Ci.nsIEnvironment);
return env.get(envString);
}//febeGetEnvironmentVariableValue
function febeInit(){
// Get setup and start the backup
// Set chrome priviledges
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
febeVersion = febeMsg[49]+" "+getFebeVersion();
febeGetPrefs();
if(!febeGetBDD()){return false;}
// Create timestamped directory if needed
if(febeUseTimestampedDir){
var timestamp = febePrefs.getCharPref("extensions.febe.timestamp.format");
if(!febeVerifyTimestamp(timestamp)){return false;}
febeDelTimestampDirs();
var d=new Date();
var YYYY = String(d.getFullYear());
var MM = String(d.getMonth()+1);
if(MM.length == 1){MM = "0" + MM;}
var DD = String(d.getDate());
if(DD.length == 1){DD = "0" + DD;}
var hh = String(d.getHours());
if(hh.length == 1){hh = "0" + hh;}
var mm = String(d.getMinutes());
if(mm.length == 1){mm = "0" + mm;}
var ss = String(d.getSeconds());
if(ss.length == 1){ss = "0" + ss;}
timestamp = timestamp.replace("YYYY",YYYY);
timestamp = timestamp.replace("MM",MM);
timestamp = timestamp.replace("DD",DD);
timestamp = timestamp.replace("hh",hh);
timestamp = timestamp.replace("mm",mm);
timestamp = timestamp.replace("ss",ss);
febeBuDesDir.append(timestamp);
if(!febeBuDesDir.exists() || !febeBuDesDir.isDirectory()){
febeBuDesDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
}//if
febeExBuDir = febeBuDesDir.path;
}//if
if(!febeCheckPending()){return false;}
if(!febeSanityCheck()){return false;}
if(!febeInitDir()){return false;}
if(!febeClearDir()){return false;}
febeStartBackup();
return true;
}//febeInit()
function febeVerifyTimestamp(timestamp){
// Verify the timestamp mask
if(timestamp == "FEBE YYYY MM-DD hh.mm.ss"){return true;} // ISO8601
if(timestamp == "FEBE YYYY DD.MM hh.mm.ss"){return true;} // European
var tmp="<style>color: red; font-weight: bold; font-size: 20px;</style>"+febeMsg[208];
tmp = tmp.replace("%TIMESTAMP%",timestamp) +"\n\n";
tmp += febeMsg[209].replace("%FORMAT1%","FEBE YYYY MM-DD hh.mm.ss")+"\n";
tmp += febeMsg[210].replace("%FORMAT2%","FEBE YYYY DD.MM hh.mm.ss")+"\n\n";
tmp += "<style>color: red; font-weight: bold; font-size: 20px;</style>"+febeMsg[211];
febeAlert(tmp);
return false;
}//febeVerifyTimestamp()
function febeVerify(verifyFileName){
//return true
// Verify backup was created
if(!febeBuInProgress()){return true;} // Don't verify restores
if(febeVerifyBackups == false){return true;}
// Check for existance of backup file every second for a maximum of 10 seconds
for(var i=0; i<5; i++){
var chkFile = febeBuDesDir.clone();
chkFile.append(verifyFileName);
if(chkFile.exists()){return true;}
febePause(1000);
}//for
return false;
}//febeVerify()
function febeGetBDD(){
// See if backup destination directory exists
var prefName = "extensions.febe.extBUdir";
if(febePrefs.prefHasUserValue(prefName)){
febeExBuDir = febeGetUnicharPref(prefName);
if(febeExBuDir == ""){
if(febePlatform == 1){febeExBuDir = "C:\\";}
if(febePlatform == 2){febeExBuDir = "/";}
if(febePlatform == 3){febeExBuDir = "/";}
}//if
febeBuDesDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
febeBuDesDir.initWithPath(febeExBuDir);
if (!(febeBuDesDir.exists() && febeBuDesDir.isDirectory())){
febeAlert(febeMsg[0]+" \""+febeExBuDir+"\" "+febeMsg[1]+"\n"+febeMsg[2]);
return false;
}//if
} else {
febeAlert(febeMsg[3]+"\n"+febeMsg[4]);
return false;
}//if
return true;
}//febeGetBDD()
function febeDelTimestampDirs(){
// Delete timestamped directories if needed
if(febeMaxDirs == 0){return true;} // No limit
var timestamp = febePrefs.getCharPref("extensions.febe.timestamp.format");
switch(timestamp){
case "FEBE YYYY MM-DD hh.mm.ss":
febeDelISO8601Dirs();
break;
case "FEBE YYYY DD.MM hh.mm.ss":
febeDelEuropeanDirs();
break;
}//switch
return true;
}//function febeDelTimestampDirs(){
function febeDelISO8601Dirs(){
// Delete ISO8601 formated directories
var dirArray = [];
var mask = /^FEBE \d\d\d\d \d\d-\d\d \d\d\.\d\d\.\d\d$/;
var buDirRoot = febeBuDesDir.clone();
var entries = buDirRoot.directoryEntries;
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
var dirName = entry.leafName;
if(!entry.isDirectory()){continue;}
if(!dirName.match(mask)){continue;}
dirArray.push(dirName);
}
var numDirsToDelete = dirArray.length - febeMaxDirs + 1;
dirArray.sort();
for(var i=0; i<numDirsToDelete; i++){
var rmDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
rmDir.initWithPath(buDirRoot.path);
rmDir.append(dirArray[i]);
rmDir.remove(true);
}//for
return true;
}//febeDelTimestampDirs()
function febeDelEuropeanDirs(){
// Delete European formated directories
var dirArray = {};
var sortArray = [];
var mask = /^FEBE \d\d\d\d \d\d.\d\d \d\d\.\d\d\.\d\d$/;
var buDirRoot = febeBuDesDir.clone();
var entries = buDirRoot.directoryEntries;
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
var dirName = entry.leafName;
if(!entry.isDirectory()){continue;}
if(!dirName.match(mask)){continue;}
var ISO8601 = febeNewDirName(0,dirName);
sortArray.push(ISO8601);
dirArray[ISO8601] = dirName;
}
sortArray.sort();
var numDirsToDelete = sortArray.length - febeMaxDirs + 1;
for(var i=0; i<numDirsToDelete; i++){
var rmDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
rmDir.initWithPath(buDirRoot.path);
var which = sortArray[i];
rmDir.append(dirArray[which]);
rmDir.remove(true);
}//for
return true;
}//febeDelEuropeanDirs()
function febeAbortBackup(){
// Abort scheduled backup before it starts (only if statusbar icon is in "warning" state)
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
var d = win.document.getElementById("febestatusbar");
if(d){
var status = d.getAttribute("status");
switch(status){
case "warning":
var tmp="<style>color: red; font-weight: bold; font-size: 20px;</style>"+febeMsg[179];
if(!febeConfirm(tmp)){return;}
for(var i in febeSetTimeoutID){
var to = new febeSetTimeoutObj;
to.PID = febeSetTimeoutID[i].PID;
to.Process = febeSetTimeoutID[i].Process;
clearTimeout(to.PID);
}//for
febeSetTimeoutID = [];
febeScheduledBuTimer.cancel();
var tmp = "<style>color: red; font-weight: bold;</style>"+febeMsg[150]+"\n";
tmp += "<style>color: black; font-weight: bold;</style>"+febeMsg[151]+"\n";
tmp += "<style>color: black; font-weight: normal;</style>"+febeMsg[152]+"\n";
febeAlert(tmp);
febePrefs.setBoolPref("extensions.febe.backupInProgress",false); // In case it tries to start, just say no ...
// Turn off scheduled backups
var prefName = "extensions.febe.schedule.frequency";
febePrefs.setCharPref(prefName,"none");
febeScheduleBackup();
break;
case "normal":
var prefName = "extensions.febe.schedule.description";
var tmp = "<style>color: blue; font-weight: normal;</style>"+febeMsg[114]+"\n";
tmp += "<style>color: black; font-weight: normal;font-family: courier;</style>"+febeGetUnicharPref(prefName);
febeAlert(tmp);
break;
case "nobackup":
var tmp = "<style>color: blue; font-weight: normal; font-size: 12px;</style>"+febeMsg[113];
febeAlert(tmp);
break;
}//switch
}//if
return true;
}//febeAbortBackup()
function febeCheckPending(){
// See if any pending extension/theme installations exist
var extDir = febeProfDir.clone();
extDir.append("extensions");
extDir.append("staged-xpis");
if(!extDir.exists()){return true;}
var pending = 0;
var entries = extDir.directoryEntries;
while(entries.hasMoreElements()){
entries.getNext();
pending++;
}//while
var style = "<style>color: red;font-size: 12pt;</style>";
var tmp = febeMsg[212].replace("%NUM%",pending);
tmp = style+tmp+"\n\n"+febeMsg[213];
return febeConfirm(tmp);
}//febeCheckPending()
function febeSanityCheck(){
// Check to see if there is anything to backup
var OK = (
buExtensions ||
buThemes ||
buBookmarks ||
buPreferences ||
buCookies ||
buUserChrome ||
buUserPwd ||
buSearchPlugins ||
buBrowserHistory ||
buFormFillHistory ||
buPermissions ||
buUDBu ||
includeFEBE ||
buProfile);
if(!OK){febeAlert(febeMsg[131]);}
return OK;
}//febeSanityCheck()
function doFebeBackup(){
febePrefs.setBoolPref("extensions.febe.backupInProgress",true);
if(!buProfile){
febeBackupExtensions();
febeBackupBookmarks();
febeBackupPreferences();
febeBackupCookies();
febeBackupUserChrome();
febeBackupPasswords();
febeBackupSearchPlugins();
febeBackupBrowserHistory();
febeBackupFormFillHistory();
febeBackupPermissions();
febeBackupUDBu();
upBackedUp = false;
}else{
febeBackupProfile();
}
febeIncludeFEBE();
febeWriteResults();
febeStoreBUdate();
try{
febeWin.close();
}catch(e){;}
febePrefs.setBoolPref("extensions.febe.backupInProgress",false);
febeScheduleBackup(); // Schedule the next backup
return true;
}//doFebeBackup()
function febeStoreBUdate(){
// Write last backup info to preferences
var prefName = "extensions.febe.lastbackup";
var dflt = new Date();
febeSetUnicharPref(prefName,dflt);
var prefName = "extensions.febe.lastbackup.folder";
febeSetUnicharPref(prefName,febeBuDesDir.path);
return true;
}//febeStoreBUdate()
function febeIncludeFEBE(){
// Include a copy of FEBE with backup
if(!includeFEBE){return;}
if(!buProfile){return;} // Only for full profile backup
var extDir = febeProfDir.clone();
extDir.append("extensions");
extDir.append(FEBE_GUID);
var srcName = extDir.clone();
srcName = srcName.path;
var extBuName = "FEBE.xpi";
febeZip(srcName,febeExBuDir,extBuName,false,false);
exBackedUp = true;
var thisExt = new febeExtInfo(FEBE_GUID);
if(!thisExt) return false;
var item = new febeExtObj;
item.Name = "FEBE";
item.Path = "";
item.Icon = thisExt.iconURL;
item.Home = thisExt.homepageURL;
item.guid = FEBE_GUID;
item.verified = febeVerify(extBuName);
febeExtensionsList[item.Name] = item;
febeExtensionsList["**total**"]++;
return true;
}//febeIncludeFEBE()
function febeWriteResults(){
// Create results page
febeUpdateProgressWindow(febeMsg[77]);
// Pointer to results page html file
var febeResultsPage = FEBEdir.clone();
febeResultsPage.append("FEBEresults.html");
// Open results page for writing
var resultsFile = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
resultsFile.init(febeResultsPage, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
// Get results template
var resultsTemplate=getFebeResultsTemplate("chrome://febe/content/FEBEresultsTemplate.html")
// Add results to results page
var middle = new String();
var cnt = 0;
// Create the new content
var numExt = parseInt(febeExtensionsList["**total**"]);
var numThemes = parseInt(febeThemesList["**total**"]);
delete febeExtensionsList["**total**"];
delete febeThemesList["**total**"];
// Sort using key array
var febeExtKey = [];
var febeThemeKey = [];
for(var i in febeExtensionsList){
febeExtKey.push(febeExtensionsList[i].Name);
}//for
for(var i in febeThemesList){
febeThemeKey.push(febeThemesList[i].Name);
}//for
febeExtKey.sort();
febeThemeKey.sort();
var total = numExt + numThemes;
if (bmBackedUp){total++};
if (prBackedUp){total++};
if (ckBackedUp){total++};
if (chBackedUp){total++};
if (ucBackedUp){total++};
if (pwBackedUp){total++};
if (pdBackedUp){total++};
if (spBackedUp){total++};
if (hsBackedUp){total++};
if (ffBackedUp){total++};
if (pmBackedUp){total++};
if (upBackedUp){total++};
total += udBackedUp;
var re = new RegExp("\\\\", "g");
var errCnt = 0;
var warnCnt = 0;
var imgstyle = ' height="16" width="16" '
var table = ['<table border="0" cellpadding="2" cellspacing="2">\n<tbody>',"</tbody>\n</table>"];
var tr = ["<tr>\n","</tr>\n"];
var tdnum = ['<td style="vertical-align: middle; text-align: right;"><num>'
,"</num></td>\n"];
var tdimg = ['<td style="text-align: center;">','</td>\n'];
var tdnolink = ['<td style="font-weight: bold;"><nolink>','</nolink></td>\n'];
var tdlink = ['<td style="font-weight: bold;">','</td>\n']
var tdguid = ['<td><guid>','</guid></td>\n'];
var div = ['<div style="text-align:left; direction: ltr;">\n',"</div>\n"];
var disabledIndicator = '<img src="chrome://febe/skin/disabled.png"'+imgstyle+'>';
var useragent = ['<useragent>','</useragent>'];
middle += febeLocalizedDate(Date())+"<br>\n";
middle += "<p><b>"+febeMsg[12]+" </b> "+total+" "+febeMsg[13];
var prefix = "file://";
if (febeExBuDir.substring(0,2) == "\\\\"){prefix = "file:///"} // add extra "\" for networked drive
middle += " <i>("+febeMsg[15]+' <a href=\"'+prefix+febeExBuDir.replace(re,"/")+'\">'+febeExBuDir+"</a>)</i></p>\n";
if ((total) != 0){
if (numExt != 0){
middle += "<p>"+febeMsg[14]+" ("+numExt+" "+febeMsg[13]+")\n";
if(febeDisabledCount != 0){
middle += "<i>("+febeMsg[107].replace("%num%",febeDisabledCount)+")</i>\n";
}else{
middle += " - "+febeMsg[120].replace("%disabled%",disabledIndicator)+"\n";
}//if
middle += "</p>\n"+div[0]+table[0];
var item = new febeExtObj;
for(var i=0; i<febeExtKey.length; i++){
var key = febeExtKey[i];
item = febeExtensionsList[key];
if(item.verified == false){
febeErrorList.push(febeMsg[18]+" "+item.Name);
errCnt++;
continue;
}//if
cnt++;
middle += tr[0];
middle += tdnum[0]+cnt+"."+tdnum[1];
middle += tdimg[0]+"<img src='"+item.Icon+"'"+imgstyle+">"+tdimg[1];
var thisExt = new febeExtInfo(item.guid);
if(!thisExt) continue;
var tmp = item.Name;
if(thisExt.isDisabled){
tmp = "<i>"+tmp+"</i>";
}else{
tmp = tmp;
}//if
if(item.Home != ""){
middle += tdlink[0]+"<a href="+item.Home+">"+tmp+"</a>"+tdlink[1];
}else{
middle += tdnolink[0]+tmp+tdnolink[1];
}//if
middle += tr[1];
}//for
middle += table[1]+div[1];
}//if
if (numThemes != 0){
cnt = 0;
middle += "<p>"+febeMsg[16]+" ("+numThemes+" "+febeMsg[13]+")</p>\n";
middle += div[0]+table[0];
var item = new febeExtObj;
for(var i=0; i<febeThemeKey.length; i++){
var key = febeThemeKey[i];
item = febeThemesList[key];
if(item.verified == false){
febeErrorList.push(febeMsg[18]+" "+item.Name);
errCnt++;
continue;
}//if
cnt++;
middle += tr[0];
middle += tdnum[0]+cnt+"."+tdnum[1];
middle += tdimg[0]+"<img src='"+item.Icon+"'"+imgstyle+">"+tdimg[1];
var tmp = item.Name;
if(item.Home){
middle += tdlink[0]+"<a href="+item.Home+">"+tmp+"</a>"+tdlink[1];
}else{
middle += tdnolink[0]+tmp+tdnolink[1];
}//if
middle += tr[1];
}//for
middle += table[1]+div[1];
}//if
//middle += div[1];
}else{
febeErrorList.push("<p>"+febeMsg[19]+"</p>\n");
errCnt++;
}//if
middle += "<p>";
if(!buProfile){
// Optional backups
if (buBookmarks){
if (bmBackedUp){
middle +=febeMsg[27]+" <b>"+bmBuName+"</b><br>\n"
}else{
febeErrorList.push(febeMsg[30]);
errCnt++;
}//if
}//if
if (buPreferences){
if (prBackedUp){
middle +=febeMsg[28]+" <b>"+prBuName+"</b><br>\n"
}else{
febeWarningList.push(febeMsg[31]);
warnCnt++;
}//if
}//if
if (buCookies){
if (ckBackedUp){
middle +=febeMsg[29]+" <b>"+ckBuName+"</b><br>\n"
}else{
febeWarningList.push(febeMsg[32]);
warnCnt++;
}//if
}//if
if (buUserChrome){
if (chBackedUp){
middle +=febeMsg[52]+" <b>"+chBuName+"</b><br>\n"
}else{
febeWarningList.push(febeMsg[60]);
warnCnt++;
}//if
}//if
if (buUserPwd){
if (pwBackedUp){
middle +=febeMsg[54]+" <b>"+pwBuName+"</b><br>\n"
}else{
febeWarningList.push(febeMsg[62]);
warnCnt++;
}//if
}//if
if (buSearchPlugins){
if (spBackedUp){
middle +=febeMsg[56]+" <b>"+spBuName+"</b><br>\n"
}else{
febeWarningList.push(febeMsg[64]);
warnCnt++;
}//if
}//if
if (buBrowserHistory){
if (hsBackedUp){
middle +=febeMsg[57]+" <b>"+hsBuName+"</b><br>\n"
}else{
febeWarningList.push(febeMsg[65]);
warnCnt++;
}//if
}//if
if (buFormFillHistory){
if (ffBackedUp){
middle +=febeMsg[58]+" <b>"+ffBuName+"</b><br>\n"
}else{
febeWarningList.push(febeMsg[66]);
warnCnt++;
}//if
}//if
if (buPermissions){
if (pmBackedUp){
middle +=febeMsg[116]+" <b>"+pmBuName+"</b><br>\n"
}else{
febeWarningList.push(febeMsg[115]);
warnCnt++;
}//if
}//if
if (buUDBu){
for(var i in febeUDBuDone){
var item = new febeUDBuDoneObj;
item.Description = febeUDBuDone[i].Description;
item.Name = febeUDBuDone[i].Name;
var tmp = febeMsg[148].replace("%description%","\""+item.Description+"\"");
tmp = tmp.replace("%name%"," <b>"+item.Name+"</b><br>\n");
middle += tmp;
}//for
}//if
}else{ // Full profile
if (upBackedUp){
middle +=febeMsg[59]+" <b>"+upBuName+"</b><br>\n"
}else{
febeErrorList.push(febeMsg[67]);
errCnt++;
}//if
}//if
middle += "</p>\n";
// Write the final results
var pageSource = resultsTemplate.replace("%title%", febeMsg[108]);
pageSource = resultsTemplate.replace("%title%", febeMsg[108]);
pageSource = pageSource.replace("%reportheading%", febeMsg[109]);
pageSource = pageSource.replace("%version%", febeVersion);
pageSource = pageSource.replace("%by%", febeMsg[180]);
pageSource = pageSource.replace("%results%", middle);
var prefName = "extensions.febe.orientation";
var orientation = febePrefs.getCharPref(prefName);
pageSource = pageSource.replace("%orientation%", orientation);
middle = "";
if(errCnt != 0){
pageSource = pageSource.replace("%errmsg%", "<errh>"+errCnt+" "+febeMsg[112]+"</errh>");
middle = div[0];
for(var i=0; i<febeErrorList.length; i++){
middle += "<err>"+febeErrorList[i]+"</err><br>\n";
}//for
middle += div[1];
pageSource = pageSource.replace("%errlist%", middle);
}else{
pageSource = pageSource.replace("%errmsg%<br>", "<!-- %errmsg% -->\n");
pageSource = pageSource.replace("%errlist%<br>", "<!-- %errlist% -->\n");
}//if
if(warnCnt != 0){
pageSource = pageSource.replace("%warnmsg%", "<warnh>"+warnCnt+" "+febeMsg[132]+"</warnh>");
middle = div[0];
for(var i=0; i<febeWarningList.length; i++){
middle += "<warn>"+febeWarningList[i]+"</warn><br>\n";
}//for
middle += div[1];
pageSource = pageSource.replace("%warnlist%", middle);
}else{
pageSource = pageSource.replace("%warnmsg%<br>", "<!-- %warnmsg% -->\n");
pageSource = pageSource.replace("%warnlist%<br>", "<!-- %warnlist% -->\n");
}//if
pageSource = pageSource.replace("%useragent%", useragent[0]+febeMsg[191] + " " + navigator.userAgent+useragent[1]);
pageSource = pageSource.replace("%hompagemsg%", febeMsg[110]);
pageSource = pageSource.replace("%linkmsg%", febeMsg[111]);
// Create an UTF-8 output stream
var charset = "UTF-8";
var os = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
os.init(resultsFile, charset, 4096, 0x0000);
os.writeString(pageSource);
os.close();
// Open and display results
if(errCnt == 0){
febePlaySound("success");
}else{
febePlaySound("failure");
}//if
//var finalPage = "file:///"+febeResultsPage.path;
var finalPage = "chrome://febe/content/febeResultsLoad.html";
if(febeDispResults){
febeOpenLink(finalPage);
}//if
if(febeSaveResults){
// Save results page with backup
var timestamp = febePrefs.getCharPref("extensions.febe.timestamp.format");
var d=new Date();
var YYYY = String(d.getFullYear());
var MM = String(d.getMonth()+1);
if(MM.length == 1){MM = "0" + MM;}
var DD = String(d.getDate());
if(DD.length == 1){DD = "0" + DD;}
var hh = String(d.getHours());
if(hh.length == 1){hh = "0" + hh;}
var mm = String(d.getMinutes());
if(mm.length == 1){mm = "0" + mm;}
var ss = String(d.getSeconds());
if(ss.length == 1){ss = "0" + ss;}
timestamp = timestamp.replace("YYYY",YYYY);
timestamp = timestamp.replace("MM",MM);
timestamp = timestamp.replace("DD",DD);
timestamp = timestamp.replace("hh",hh);
timestamp = timestamp.replace("mm",mm);
timestamp = timestamp.replace("ss",ss);
var dName = febeMsg[76]+" - "+timestamp+".html";
febeCopyFile(febeResultsPage.path,febeBuDesDir.path,dName);
}//if
// Upload to box.net
var prefName = "extensions.febe.boxnet.enabled";
var enabled = febePrefs.getBoolPref(prefName);
var prefName = "extensions.febe.boxnet.autoupload";
var upload = febePrefs.getBoolPref(prefName);
if(enabled && upload){
window.openDialog('chrome://febe/content/BoxNet.html','FEBE upload', 'chrome,alwaysRaised,centerscreen,resizable,minimizable',febeMsg);
}//if
return true;
}//febeWriteResults()
function febeWarn(){
// Display scheduled backup warning in statusbar
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
var d = win.document.getElementById("febestatusbar");
d.setAttribute("status","warning");
febePlaySound("warning");
for(var i=10000; i<= 40000; i += 10000){
var to = new febeSetTimeoutObj;
to.PID = setTimeout('febePlaySound("warning")',i)
to.Process = 'febePlaySound("warning")';
febeSetTimeoutID.push(to);
}//for
return true;
}//febeWarn()
function febeDebug(aMsg) {
setTimeout(function() { throw new Error("[debug] " + aMsg); }, 0);
return true;
}//debug
function febePickFiles(filter,msgNum){
// Select extension/themes to install
const nsIFilePicker = Ci.nsIFilePicker;
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, febeMsg[msgNum], nsIFilePicker.modeOpenMultiple);
fp.appendFilter(filter,filter);
// Set the default directory to the backup destination directory
var prefName = "extensions.febe.extBUdir";
if(!febePrefs.prefHasUserValue(prefName)){
febeGetPrefs();
if(febePlatform == 1){febeExBuDir = "C:\\";}
if(febePlatform == 2){febeExBuDir = "/";}
if(febePlatform == 3){febeExBuDir = "/";}
}else{
febeExBuDir = febeGetUnicharPref(prefName);
}//if
if(febeExBuDir != ""){
var aDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
aDir.initWithPath(febeExBuDir);
fp.displayDirectory = aDir;
}//if
var rv = fp.show();
febeETinstall = [];
if (rv == nsIFilePicker.returnOK){
var files = fp.files;
while(files.hasMoreElements()) {
var file = files.getNext()
.QueryInterface(Ci.nsILocalFile);
var obj = new febeExtObj;
obj.Name = file.leafName;
obj.Path = file.path;
febeETinstall.push(obj);
}//while
}//if
return true;
}//febePickFiles()
function febeStartBackup(){
if(febeBuInProgress()){
if(!febeBuInProgressCheck()) {return false;}
}//if
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
try{
if(win.document.getElementById("febeTLBRbutton")){
win.document.getElementById("febeTLBRbutton").status = "disabled";
win.document.getElementById("febeTLBRbutton").hidden = "true";
}//if
if(!febeHideIcons){
win.document.getElementById("febestatusbar").hidden = true;
}//if
}catch(e){;}
febePrefs.setBoolPref("extensions.febe.backupInProgress",true);
if(febeDispProgress == true){
// Open the progress window
febeWin = openDialog("chrome://febe/content/febeProgress.xul", "FEBE", "chrome,alwaysRaised,centerscreen,dialog='no'");
// Give the browser a chance to display the progress window before the backup starts
setTimeout('doFebeBackup()',1000);
}else{
doFebeBackup();
}//if
try{
if(win.document.getElementById("febeTLBRbutton")){
win.document.getElementById("febeTLBRbutton").setAttribute("status","normal");
win.document.getElementById("febeTLBRbutton").setAttribute("hidden","false");
}//if
if(!febeHideIcons){
win.document.getElementById("febestatusbar").class = "statusbarpanel-iconic febe-normal";
win.document.getElementById("febestatusbar").hidden = false;
}//if
}catch(e){;}
return true;
}//febeStartBackup()
function getFebeResultsTemplate(aURL){
var req = new XMLHttpRequest();
req.open('GET', aURL, false);
req.send(null);
return req.responseText;
}//getFebeResultsTemplate()
function febeDirCopy(sourceDir){
// Recursively copy individual files and sub-directories to a destination directory
//
// Example:
// sourceDir (intially) = [profiledir]/extensions
// febeSubRootDir = {4BBDD651-70CF-4821-84F8-2B918CF89CA3}
// febeDestDir = nsIFile to [temp]/febe.tmp
//
// All files and sub-directories in [profiledir]/extensions/{4BBDD651-70CF-4821-84F8-2B918CF89CA3}
// will be copied to [temp]/febe.tmp/{4BBDD651-70CF-4821-84F8-2B918CF89CA3}
var tmp = "sourceDir: "+sourceDir;
tmp += "\nfebeSubRootDir: "+febeSubRootDir;
tmp += "\nfebeDestDir: "+febeDestDir.path;
var aFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
if (!aFile) return false;
aFile.initWithPath(sourceDir);
var entries = aFile.directoryEntries;
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
var src = entry.path;
var p = src.indexOf(febeSubRootDir)
if(p == -1){continue;}
if(entry.isDirectory()){
febeDirCopy(src);
}else{
var parentPath = entry.parent.path;
var dest = febeDestDir.path+"\\"+parentPath.substring(p);
var file = entry.leafName;
febeCopyFile(src,dest,file);
}//if
}//while
return true;
}//febeDirCopy()
function febePickFile(filter,msgNum){
// Select a file to restore
const nsIFilePicker = Ci.nsIFilePicker;
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, febeMsg[msgNum], nsIFilePicker.modeOpen);
// Fix for mac - Can't handle strings like "bookmarks*.json". - Change to "*.json"
if(febePlatform == 3){
var n = filter.indexOf("*");
filter = filter.substr(n);
}//if
fp.appendFilter(filter,filter);
// Set the default directory to the backup destination directory
var prefName = "extensions.febe.extBUdir";
if(!febePrefs.prefHasUserValue(prefName)){
febeGetPrefs();
if(febePlatform == 1){febeExBuDir = "C:\\";}
if(febePlatform == 2){febeExBuDir = "/";}
if(febePlatform == 3){febeExBuDir = "/";}
}else{
febeExBuDir = febeGetUnicharPref(prefName);
}//if
if(febeExBuDir != ""){
var aDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
aDir.initWithPath(febeExBuDir);
fp.displayDirectory = aDir;
}//if
var rv = fp.show();
if (rv == nsIFilePicker.returnOK){
rv = fp.file;
febePathName = rv.path;
febePrName = febePfName = rv.leafName;
febePfParent = rv.parent.path;
return true;
}//if
return false;
}//febePickFile()
function febeConfirmRestore(msgNum,bDate){
var style = "<style>color: red;font-size: 14pt;</style>";
var tmp = style+febeMsg[36] +"\n";
tmp += febeMsg[msgNum] + "\n";
if(bDate != ""){tmp += febeLocalizedDate(bDate) + "\n";}
tmp += "\n";
if(bDate != ""){tmp += febeMsg[45] + "\n";}
tmp += febeMsg[40];
tmp += "\n" + febeMsg[41];
return febeConfirm(tmp);
}//febeConfirmRestore()
function febeGetBuDate(filename){
var oFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
oFile.initWithPath(filename);
febeBUdate = new Date(oFile.lastModifiedTime);
return true;
}//febeGetBuDate()
function febeRestartFx(){
// Borrowed from Jed Brown's "Restart Firefox" extension
a = Ci.nsIAppStartup,Cc["@mozilla.org/toolkit/app-startup;1"].getService(a).quit(a.eRestart | a.eAttemptQuit);
return true;
}//febeRestartFx()
function febePause(millis){
date = new Date();
var curDate = null;
do { var curDate = new Date(); }
while(curDate-date < millis);
return true;
}//febePause()
function febeUpdateProgressWindow(pMsg){
if(!febeDispProgress) return true;
var pMsgField = febeWin.document.getElementById("febeProgressText");
if(pMsgField){pMsgField.setAttribute("value",pMsg)};
return true;
}//febeUpdateProgressWindow()
function febeInitDir(){
exBackedUp = false;
thBackedUp = false;
bmBackedUp = false;
prBackedUp = false;
ckBackedUp = false;
chBackedUp = false;
ucBackedUp = false;
pwBackedUp = false;
pdBackedUp = false;
spBackedUp = false;
hsBackedUp = false;
ffBackedUp = false;
pmBackedUp = false;
upBackedUp = false;
// Get platform
febePlatform = febeGetPlatform();
// Get pointer to FEBE extension directory
FEBEdir = Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager)
.getInstallLocation(FEBE_GUID)
.getItemLocation(FEBE_GUID);
if(febeInitialized == true){return true;} // Only run the rest of this routine once
febeInitialized = true;
// Create pointer to profile directory
febeProfDir = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("ProfD", Ci.nsIFile);
// Get profile name
var tmp = "";
for (i = febeProfDir.path.length; i > 0; i--){
var c = febeProfDir.path.charAt(i);
var delimiter = "\\"
if(febePlatform == 2){delimiter = "/";} // *nix
if(febePlatform == 3){delimiter = "/";} // Mac
if( c == delimiter ){
break;
}else{
tmp = c + tmp;
}
}//for
var p = tmp.indexOf(".")
febeProfName = tmp.substr(p+1);
return true;
}//febeInitDir()
function febeClearDir(){
// Clear destination directory
if(febeClearDestDir == false){return true;}
var entries = febeBuDesDir.directoryEntries;
var numFiles = 0;
var numDirs = 0;
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
if(entry.isFile()){numFiles++;}
if(entry.isDirectory()){numDirs++;}
}//while
// Warn before delete?
var clearWarning = new Boolean(false);
var prefName = "extensions.febe.clearwarning";
if(febePrefs.prefHasUserValue(prefName)){
clearWarning = febePrefs.getBoolPref(prefName);
} else {
febePrefs.setBoolPref(prefName,true);
clearWarning = false;
}//if
if((clearWarning) && numFiles != 0){
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
var checkResult = {};
var x1 = new RegExp("x1");
var x2 = new RegExp("x2");
var tmp = febeMsg[99];
tmp = tmp.replace(x1,numFiles);
tmp = tmp.replace(x2,numDirs);
tmp += "\n"+febeMsg[100];
var OK = febeConfirm(tmp);
if(!OK){return false;}
}//if
var entries = febeBuDesDir.directoryEntries;
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
if(entry.isFile()){entry.remove(false);}
}//while
return true;
}//febeClearDir()
function febeDosHappy(aString){
// Mask out DOS incompatable characters
if(febePlatform != 1){return aString;}
var goodList = " .@-_";
goodList += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
goodList += "abcdefghijklmnopqrstuvwxyz";
goodList += "0123456789";
for (var i = 0; i < aString.length; i++){
var c = aString.charAt(i);
var OK = new Boolean(false);
for (var j = 0; j < goodList.length; j++){
var tChar = goodList.charAt(j);
//print(c+" : "+tChar+" : "+OK)
if(c == tChar){
OK = true;
break;
}//if
}//for
if(OK == false){aString = aString.replace(c,"_");}
}//for
return aString;
}//febeDosHappy
function febeOpenLink(URL){
if(!URL){return true;}
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
var febeGetBrowser = win.getBrowser();
var currBlank = (febeGetBrowser &&
(febeGetBrowser.mCurrentTab.linkedBrowser &&
(febeGetBrowser.mCurrentTab.linkedBrowser.contentDocument.location == "about:blank")) ||
(!febeGetBrowser.mCurrentTab.linkedBrowser &&
(febeGetBrowser.mCurrentTab.label == "(Untitled)")));
if (currBlank)
{
var resultsWindow = win.loadURI(URL);
} else {
var resultsWindow = win.openNewTabWith(URL, this.docURL, null, null);
}//if
return true;
}febeOpenLink()
function febeRestoreProgress(){
febeGetPrefs();
if(febeDispProgress == true){
// Open the progress window
febeWin = openDialog("chrome://febe/content/febeRestore.xul", "FEBE", "chrome,dependent,alwaysRaised,centerscreen,dialog='no'");
febeWin.focus();
// Give the browser a chance to display the progress window before the restore starts
febePause(1000);
}//if
return true;
}//febeRestoreProgress()
// ------------------ Backup Functions --------------------
function febeBackupExtensions(){
// Backup extensions and themes
var extDir = febeProfDir.clone();
extDir.append("extensions");
var entries = extDir.directoryEntries;
febeExtensionsList = {};
febeThemesList = {};
febeErrorList = [];
febeWarningList = [];
febeDisabledCount = 0;
febeExtensionsList["**total**"] = 0; // Associative arrays don't have a
febeThemesList["**total**"] = 0; // 'length' property ... So keep count
if(buExtensions == false && buThemes == false){return true;}
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
if(!entry.isDirectory()){continue;} // Don't process junk in the extension directory
extGUID = entry.leafName;
// Get info for item
var thisExt = new febeExtInfo(extGUID);
if(!thisExt) continue;
var eType = thisExt.type; // 2=Extension, 4=Theme
if(eType != 2 && eType != 4){continue;} // Not an extension or theme ... what is it?
if(eType == 2 && buExtensions == false){
continue; // Not backing up extensions at this time
}else{
exBackedUp = true;
}//if
if(eType == 4 && buThemes == false){
continue; // Not backing up themes at this time
}else{
thBackedUp = true;
}//if
var extIsDisabled = thisExt.isDisabled;
if(ignoreDisabled == true){
if(extIsDisabled != false){
febeDisabledCount++;
continue;
}//if
}//if
var extName = thisExt.name;
var extVer = febeStripSpaces(thisExt.version);
var extIcon = thisExt.iconURL;
if(extIsDisabled){extIcon = "chrome://febe/skin/disabled.png";}
var extHome = thisExt.homepageURL;
febeExtExt = ".xpi";
if(eType == 4){febeExtExt = ".jar"};
var extBuName = febeStripSpaces(extName)+"{" + extVer + "}"+febeExtExt;
var srcName = extDir.clone();
srcName.append(extGUID);
srcName = srcName.path;
febeZip(srcName,febeExBuDir,extBuName,false,false);
var item = new febeExtObj;
item.Name = extBuName;
item.Path = "";
item.Icon = extIcon;
item.Home = extHome;
item.guid = extGUID;
item.Type = eType;
item.verified = febeVerify(extBuName);
if(eType == 2){
febeExtensionsList[item.Name] = item;
febeExtensionsList["**total**"]++;
}else{
febeThemesList[item.Name] = item;
febeThemesList["**total**"]++;
}//if
}//while
return true;
}//febeBackupExtensions()
function febeBackupBookmarks(){
bmBackedUp = false;
if (!buBookmarks){return true;}
bmBuName ="bookmarks{" + febeProfName + "}.json";
var dFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dFile.initWithPath(febeExBuDir);
dFile.append(bmBuName);
PlacesUtils.backupBookmarksToFile(dFile);
bmBackedUp = febeVerify(bmBuName);
return true;
}//febeBackupBookmarks()
function febeBackupPreferences(){
prBackedUp = false;
if (!buPreferences){return true;}
var profileDir = febeProfDir.clone();
profileDir.append("prefs.js");
var srcFile = profileDir.path
prBuName ="prefs{" + febeProfName + "}.js";
if (febeCopyFile(srcFile,febeExBuDir,prBuName)){prBackedUp = febeVerify(prBuName);}
return true;
}//febeBackupPreferences()
function febeBackupCookies(){
ckBackedUp = false;
if (!buCookies){return true;}
ckBuName ="cookies{" + febeProfName + "}.json";
var dFile, fos, cos;
var cookieManager = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
dFile = febeBuDesDir.clone();
dFile.append(ckBuName);
fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(dFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
cos = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
cos.init(fos, "UTF-8", 0, 0x0000);
var cnt = 0;
var iter = cookieManager.enumerator;
while (iter.hasMoreElements()){
var cookie = iter.getNext();
if (cookie instanceof Ci.nsICookie){
var cookieObj = new febeCookieObj(
cookie.expires,
cookie.host,
cookie.isDomain,
cookie.isSecure,
cookie.name,
cookie.path,
cookie.policy,
cookie.status,
cookie.value);
cookieObj.expires = cookie.expires * 1000; // Convert seconds to milliseconds
var jstr = JSON.encode(cookieObj);
cos.writeString(jstr+"\n");
cnt++;
}//if
}//while
cos.close();
fos.close();
ckBackedUp = febeVerify(ckBuName);
return true;
}//febeBackupCookies()
function febeBackupUserChrome(){
chBackedUp = false;
if (!buUserChrome){return true;}
var profileDir = febeProfDir.clone();
profileDir.append("chrome");
if (!profileDir.exists()){return true;}
var srcDir = profileDir.path;
chBuName ="userChrome{" + febeProfName + "}.fbu";
febeZip(srcDir,febeExBuDir,chBuName,false,false);
chBackedUp = febeVerify(chBuName);
return true;
}//febeBackupUserChrome()
function febeBackupPasswords(){
pwBackedUp = false;
if (!buUserPwd){return true;}
pwBuName = "usernames-passwords{" + febeDosHappy(febeProfName) + "}.json";
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
var hostname, formSubmitURL, httprealm, username, password, usernameField, passwordField
var loginManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
var dFile, fos, cos;
dFile = febeBuDesDir.clone();
dFile.append(pwBuName)
fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(dFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
cos = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
cos.init(fos, "UTF-8", 0, 0x0000);
var logins = loginManager.getAllLogins({});
for (var i = 0; i < logins.length; i++) {
login = {};
login.hostname = logins[i].hostname;
login.formSubmitURL = logins[i].formSubmitURL;
login.httpRealm = logins[i].httpRealm;
login.username = logins[i].username;
login.usernameField = logins[i].usernameField;
login.password = febeObfuscate(true,logins[i].password);
login.passwordField = logins[i].passwordField;
var jstr = JSON.encode(login);
cos.writeString(jstr+"\n");
}//for
cos.close();
fos.close();
pwBackedUp = febeVerify(pwBuName);
return true;
}//febeBackupPasswords()
function febeBackupSearchPlugins(){
spBackedUp = false;
if (!buSearchPlugins){return true;}
// See if search plugins exist
var profileDir = febeProfDir.clone();
profileDir.append("searchplugins");
if (!(profileDir.exists() && profileDir.isDirectory())){return true;}
spBuName = "searchPlugins{" + febeDosHappy(febeProfName) + "}.fbu";
var srcName = febeProfDir.clone();
srcName.append("searchplugins");
srcName = srcName.path;
febeZip(srcName,febeExBuDir,spBuName,false,false);
spBackedUp = febeVerify(spBuName);
return true;
}//febeBackupSearchPlugins()
function febeBackupBrowserHistory(){
hsBackedUp = false;
if (!buBrowserHistory){return true;}
hsBuName ="history{" + febeProfName + "}.json";
var dFile, fos, cos;
var historyService = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
dFile = febeBuDesDir.clone();
dFile.append(hsBuName);
fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(dFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
cos = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
cos.init(fos, "UTF-8", 0, 0x0000);
// Get all history entries
var options = historyService.getNewQueryOptions();
var query = historyService.getNewQuery();
var result = historyService.executeQuery(query, options);
var rr = result.root;
rr.containerOpen = true;
cnt = 0;
for (var i = 0; i < rr.childCount; ++i) {
var childNode = rr.getChild(i);
var type = childNode.type;
if(type != rr.RESULT_TYPE_URI) continue;
var obj = {aURI : childNode.uri, aTitle : childNode.title, aLastVisited : childNode.time};
var jstr = JSON.encode(obj);
cos.writeString(jstr+"\n");
cnt++;
}//for
cos.close();
fos.close();
hsBackedUp = febeVerify(hsBuName);
return true;
}//febeBackupBrowserHistory()
function febeBackupFormFillHistory(){
ffBackedUp = false;
if (!buFormFillHistory){return true;}
ffBuName ="ffhistory{" + febeProfName + "}.json";
var dFile, fos, cos;
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
outFile = febeBuDesDir.clone();
outFile.append(ffBuName);
var dbFile = febeProfDir.clone();
dbFile.append("formhistory.sqlite");
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
var db = storageService.openDatabase(dbFile);
fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(outFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
cos = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
cos.init(fos, "UTF-8", 0, 0x0000);
var cnt = 0;
var sQuery = "SELECT * FROM moz_formhistory";
var stmt = db.createStatement(sQuery);
while (stmt.executeStep()) {
var obj = {id : stmt.getString(0), fieldname : stmt.getString(1), value : stmt.getString(2)};
var jstr = JSON.encode(obj);
cos.writeString(jstr+"\n");
cnt++;
}//while
cos.close();
fos.close();
ffBackedUp = febeVerify(ffBuName);
return true;
}//febeBackupFormFillHistory()
function febeBackupPermissions(){
pmBackedUp = false;
if (!buPermissions){return true;}
pmBuName ="permissions{" + febeProfName + "}.json";
var dFile, fos, cos;
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
outFile = febeBuDesDir.clone();
outFile.append(pmBuName);
var dbFile = febeProfDir.clone();
dbFile.append("permissions.sqlite");
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
var db = storageService.openDatabase(dbFile);
fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(outFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
cos = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
cos.init(fos, "UTF-8", 0, 0x0000);
var cnt = 0;
var sQuery = "SELECT * FROM moz_hosts";
var stmt = db.createStatement(sQuery);
while (stmt.executeStep()) {
var obj = {id : stmt.getString(0), host : stmt.getString(1), type : stmt.getString(2), permission : stmt.getString(3)};
var jstr = JSON.encode(obj);
cos.writeString(jstr+"\n");
cnt++;
}//while
cos.close();
fos.close();
pmBackedUp = febeVerify(pmBuName);
return true;
}//febeBackupPermissions()
function febeBackupUDBu(){
if (!buUDBu){return true;}
udBackedUp = 0;
febeUDBuDone = [];
if(!febeUDBuInit()){return false;} // UDBU is empty
for(var i in febeUDBuList){
var Label = new String(febeUDBuList[i].Label);
if(Label.length == 0){continue;} // Datafile is empty?
var Type = new Number(febeUDBuList[i].Type);
var Description = new String(febeUDBuList[i].Description);
var Path = new String(febeUDBuList[i].Path);
var Include = new Boolean(false);
Include = febeUDBuList[i].Include;
var item = new febeUDBuDoneObj;
item.Description = Description;
item.Type = Type; // Not really needed ... just for completeness
if(Include == "false"){continue;}
if(Type == 1){ // Folder
udBuName = Label+"{" + febeDosHappy(febeProfName) + "}.fbu";
var srcName = Path;
item.Name = udBuName;
febeZip(srcName,febeExBuDir,udBuName,true,false);
if(febeVerify(udBuName)){
udBackedUp++;
}else{
item.Description = "*** Error backing up "+Description;
}//if
febeUDBuDone[Label] = item;
}else{ // File
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(Path);
var UDBuName = Label+"{"+febeProfName+"}-"+file.leafName;
item.Name = UDBuName;
if(file.exists()){
febeCopyFile(Path,febeExBuDir,UDBuName);
}else{
var style = "<style>color: red;font-size: 12pt;</style>";
var tmp = style+febeMsg[166].replace("%path%",Path)+"\n"
febeAlert(tmp);
}//if
if(febeVerify(UDBuName)){
udBackedUp++;
}else{
item.Description = febeMsg[167].replace("%description%",Description);
}//if
febeUDBuDone[Label] = item;
}//if
}//for
return true;
}//febeBackupUDbu()
function febeBackupProfile(){
upBackedUp = false;
febeExtensionsList = [];
febeThemesList = [];
febeExtensionsList["**total**"] = 0; // Associative arrays don't have a
febeThemesList["**total**"] = 0; // 'length' property ... So keep count
if (!buProfile){return true;}
upBuName = "profileFx3{" + febeProfName + "}.fbu";
var srcName = febeProfDir.clone();
srcName = srcName.path;
febeZip(srcName,febeExBuDir,upBuName,false,false);
upBackedUp = febeVerify(upBuName);
return true;
}//febeBackupProfile()
// ------------------ End of Backup Functions -------------
// ------------------ Restore Functions -------------------
function febeRestoreExtensions(){
if(!febeInitDir()){return false;}
febePickFiles("*.xpi",25);
var xpi = new Array();
for (var i = 0; i < febeETinstall.length; i++){
var tmp = "file:///" + febeETinstall[i].Path;
var name = febeETinstall[i].Name;
xpi[name]=tmp;
}//for
InstallTrigger.install(xpi);
return true;
}//febeRestoreExtensions()
function febeRestoreThemes(){
if(!febeInitDir()){return false;}
febePickFiles("*.jar",24);
var jar = new Array();
for (var i = 0; i < febeETinstall.length; i++){
var tmp = "file:///" + febeETinstall[i].Path;
var name = febeETinstall[i].Name;
jar[name]=tmp;
}//for
InstallTrigger.install(jar);
return true;
}//febeRestoreThemes()
function febeRestoreBookmarks(){
if(!febeInitDir()){return false;}
febePathName = ""
if(!febePickFile("bookmarks*.json",33)){return true};
var check1 = febePrName.indexOf("bookmarks{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.json");
if(check1 != 0 || check2 != 6){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[50].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
febeGetBuDate(febePathName);
if(febeConfirmRestore(37,febeBUdate)){
var dFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dFile.initWithPath(febePathName);
PlacesUtils.restoreBookmarksFromJSONFile(dFile);
febeAlert(febeMsg[42]);
}else{
febeAlert(febeMsg[46]);
}
return true;
}//febeRestoreBookmarks()
function febeRestorePreferences(){
if(!febeInitDir()){return false;}
febePathName = ""
if(!febePickFile("prefs*.js",34)){return true};
var check1 = febePrName.indexOf("prefs{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.js");
if(check1 != 0 || check2 != 4){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[69].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
febeGetBuDate(febePathName);
if(febeConfirmRestore(38,febeBUdate)){
// Pointer to preferences
var oldPrefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
// Pointer to new (restored) preferences
var newPrefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
// Pointer to backed up preferences file
var newPrefFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
// Get pointer to "Prefs.js"
var PrefsFile = febeProfDir.clone();
PrefsFile.append("prefs.js")
newPrefFile.initWithPath(febePathName); // Initialize backed up prefs file
oldPrefs.deleteBranch(""); // Delete old preferences
newPrefs.readUserPrefs(newPrefFile); // Read in backed up preferences
newPrefs.savePrefFile(PrefsFile); // Save the restored preferences file
febeAlert(febeMsg[43]);
febeRestartFx(); // Restart Firefox
}else{
febeAlert(febeMsg[46]);
}
return true;
}//febeRestorePreferences()
function febeRestoreCookies(){
if(!febeInitDir()){return false;}
febePathName = ""
if(!febePickFile("cookies*.json",35)){return true};
var check1 = febePrName.indexOf("cookies{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.json");
if(check1 != 0 || check2 != 6){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[71].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
febeGetBuDate(febePathName);
if(febeConfirmRestore(39,febeBUdate)){
Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager).removeAll();
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var cookieSvc = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
var dFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dFile.initWithPath(febePathName);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
fis.init(dFile, 0x01, 0444, 0);
fis.QueryInterface(Ci.nsILineInputStream);
var cis = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
cis.init(fis,"UTF-8", 0, 0x0000);
var lis = cis.QueryInterface(Ci.nsIUnicharLineInputStream);
// read lines into array and parse into individual fields
var line = {}, hasmore;
var cnt = 0;
do {
hasmore = lis.readLine(line);
var cookie = JSON.decode(line.value)
var url = "http" + ((cookie.isSecure)?"s":"") + "://" + cookie.host + (cookie.path || "").replace(/^(?!\/)/, "/");
var cookieUri = ios.newURI(url, null, null);
var dt = new Date()
dt.setTime(cookie.expires)
var str = cookie.name+"="+cookie.value+";domain="+cookie.host+";expires="+dt.toUTCString();
cookieSvc.setCookieString(cookieUri, null, str, null);
//document.cookie = unescape(str); // Commit the cookie
cnt++;
} while(hasmore);
febeAlert(febeMsg[44]);
}else{
febeAlert(febeMsg[46]);
}//if
cis.close();
fis.close();
return true;
}//febeRestoreCookies()
function febeRestoreUserChrome(){
if(!febeInitDir()){return false;}
febePathName = ""
var chromeDir = febeProfDir.clone();
chromeDir.append("chrome");
if(!febePickFile("userChrome*.fbu",78)){return true};
var check1 = febePrName.indexOf("userChrome{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.fbu");
if(check1 != 0 || check2 != 5){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[83].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
febeGetBuDate(febePathName);
if(febeConfirmRestore(68,febeBUdate)){
var sourceDir = febePfParent;
var destDir = chromeDir.path;
var zipName = febePfName;
febeUnzip(sourceDir,destDir,zipName);
febeChmod(destDir);
febeAlert(febeMsg[79]);
}else{
febeAlert(febeMsg[46]);
}
return true;
}//febeRestoreUserChrome()
function febeRestorePasswords(){
if(!febeInitDir()){return false;}
febePathName = ""
if(!febePickFile("usernames-passwords*.json",80)){return true};
var check1 = febePrName.indexOf("usernames-passwords{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.json");
if(check1 != 0 || check2 != 6){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[125].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
febeGetBuDate(febePathName);
if(febeConfirmRestore(70,febeBUdate)){
// Clear existing paswords
var hostname, formSubmitURL, httprealm, username, password, usernameField, passwordField
var loginManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
var logins = loginManager.getAllLogins({});
for (var i = 0; i < logins.length; i++) {
//login = new nsLoginInfo(hostname, formSubmitURL, httprealm, username, password, usernameField, passwordField);
login = {};
login.hostname = logins[i].hostname;
login.formSubmitURL = logins[i].formSubmitURL;
login.httpRealm = logins[i].httpRealm;
login.username = logins[i].username;
login.usernameField = logins[i].usernameField;
login.password = logins[i].password;
login.passwordField = logins[i].passwordField;
loginManager.removeLogin(login);
}//for
dFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dFile.initWithPath(febePathName);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
fis.init(dFile, 0x01, 0444, 0);
fis.QueryInterface(Ci.nsILineInputStream);
var cis = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
cis.init(fis,"UTF-8", 0, 0x0000);
var lis = cis.QueryInterface(Ci.nsIUnicharLineInputStream);
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",Ci.nsILoginInfo,"init");
var line = {}, hasmore;
var cnt = 0;
do {
hasmore = lis.readLine(line);
var data = JSON.decode(line.value)
login = new nsLoginInfo(hostname, formSubmitURL, httprealm, username, password, usernameField, passwordField);
login.hostname = data.hostname;
login.formSubmitURL = data.formSubmitURL;
login.httpRealm = data.httpRealm;
login.username = data.username;
login.usernameField = data.usernameField;
login.password = febeObfuscate(false,data.password);
login.passwordField = data.passwordField;
try{
loginManager.addLogin(login);
cnt++;
}catch(e){
var err = e;
var tmp = "<style>color: red; font-weight: bold; font-size: 10px;</style>"+err+"\n";
tmp += "Host: "+login.hostname+"\n"
tmp += "Username: "+login.username+"\n\n";
tmp += "<style>color: black; font-weight: bold; font-size: 12px;</style>"
tmp += "Login entry skipped";
febeAlert(tmp);
}
} while(hasmore);
febeAlert(febeMsg[81]);
}else{
febeAlert(febeMsg[46]);
}//if
cis.close();
fis.close();
return true;
}//febeRestorePasswords()
function febeRestoreSearchPlugins(){
if(!febeInitDir()){return false;}
febePathName = ""
if(!febePickFile("searchPlugins*.fbu",84)){return true};
var check1 = febePrName.indexOf("searchPlugins{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.fbu");
if(check1 != 0 || check2 != 5){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[55].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
febeGetBuDate(febePathName);
if(febeConfirmRestore(72,febeBUdate)){
var profileDir = febeProfDir.clone();
profileDir.append("searchplugins");
if (!(profileDir.exists() && profileDir.isDirectory())){
// Create firedctory
profileDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
}//if
var zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
zipFile.initWithPath(febePathName);
var sourceDir = zipFile.parent.path;
var destDir = profileDir.path;
var zipName = zipFile.leafName
febeUnzip(sourceDir,destDir,zipName);
febeChmod(destDir);
febeAlert(febeMsg[85]);
}else{
febeAlert(febeMsg[46]);
}//if
return true;
}//febeRestoreSearchPlugins()
function febeRestoreBrowserHistory(){
if(!febeInitDir()){return false;}
febePathName = ""
if(!febePickFile("history*.json",86)){return true};
var check1 = febePrName.indexOf("history{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.json");
if(check1 != 0 || check2 != 6){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[63].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
febeGetBuDate(febePathName);
if(febeConfirmRestore(73,febeBUdate)){
febeRestoreProgress();
// Delete current history
var bh = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsIBrowserHistory);
bh.removeAllPages();
try {
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
os.notifyObservers(null, "browser:purge-session-history", "");
}
catch (e) { }
// Clear last URL of the Open Web Location dialog
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
try {
prefs.clearUserPref("general.open_location.last_url");
}
catch (e) { }
// Restore browser history
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var cookieSvc = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
var dFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dFile.initWithPath(febePathName);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
fis.init(dFile, 0x01, 0444, 0);
fis.QueryInterface(Ci.nsILineInputStream);
var cis = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
cis.init(fis,"UTF-8", 0, 0x0000);
var lis = cis.QueryInterface(Ci.nsIUnicharLineInputStream);
// read lines into array and parse into individual fields
var line = {}, hasmore;
var cnt = 0;
do {
hasmore = lis.readLine(line);
var histObj = JSON.decode(line.value);
// create an nsIURI
var uri = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService).newURI(histObj.aURI, null, null);
try{
bh.addPageWithDetails(uri, histObj.aTitle, histObj.aLastVisited)
}catch(e){
var msg = "\n\naURI: "+histObj.aURI+"\naTitle: "+histObj.aTitle+"\naLastVisited: "+histObj.aLastVisited;
febeFatal(e, msg)
return false;
}//try/catch
cnt++;
} while(hasmore);
febeWin.close();
febeAlert(febeMsg[106]);
}else{
febeWin.close();
febeAlert(febeMsg[46]);
}//if
cis.close();
fis.close();
return true;
}//febeRestoreBrowserHistory()
function febeRestoreFormFillHistory(){
if(!febeInitDir()){return false;}
febePathName = ""
if(!febePickFile("ffhistory*.json",88)){return true};
var check1 = febePrName.indexOf("ffhistory{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.json");
if(check1 != 0 || check2 != 6){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[82].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
febeGetBuDate(febePathName);
if(febeConfirmRestore(74,febeBUdate)){
// Get database file in profile folder
var dbFile = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
dbFile.append("formhistory.sqlite");
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
var db = storageService.openDatabase(dbFile);
var stmt;
db.beginTransactionAs(db.TRANSACTION_DEFERRED);
// Delete the existing table
stmt = db.createStatement("DELETE FROM `moz_formhistory`");
stmt.execute();
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var inFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
inFile.initWithPath(febePathName);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
fis.init(inFile, 0x01, 0444, 0);
fis.QueryInterface(Ci.nsILineInputStream);
var cis = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
cis.init(fis,"UTF-8", 0, 0x0000);
var lis = cis.QueryInterface(Ci.nsIUnicharLineInputStream);
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
// Read the backup file
var line = {}, hasmore;
var cnt = 0;
do {
hasmore = lis.readLine(line);
obj = JSON.decode(line.value);
var sQuery = "INSERT INTO moz_formhistory VALUES ('"+febeEscape(obj.id)+"','"+febeEscape(obj.fieldname)+"','"+febeEscape(obj.value)+"')"
stmt = db.createStatement(sQuery);
stmt.execute();
cnt++;
} while(hasmore);
db.commitTransaction();
febeAlert(febeMsg[89]);
}else{
febeAlert(febeMsg[46]);
}
return true;
}//febeRestoreFormFillHistory()
function febeRestorePermissions(){
if(!febeInitDir()){return false;}
febePathName = ""
if(!febePickFile("permissions*.json",117)){return true};
var check1 = febePrName.indexOf("permissions{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.json");
if(check1 != 0 || check2 != 6){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[96].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
febeGetBuDate(febePathName);
if(febeConfirmRestore(118,febeBUdate)){
// Get database file in profile folder
var dbFile = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
dbFile.append("permissions.sqlite");
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
var db = storageService.openDatabase(dbFile);
var stmt;
// Delete the existing table
stmt = db.createStatement("DROP TABLE `moz_hosts`");
stmt.execute();
// Create a new table
stmt = db.createStatement("CREATE TABLE moz_hosts ( id INTEGER PRIMARY KEY,host TEXT,type TEXT,permission INTEGER)");
stmt.execute();
// Clean it up
stmt = db.createStatement("VACUUM");
stmt.execute();
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var inFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
inFile.initWithPath(febePathName);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
fis.init(inFile, 0x01, 0444, 0);
fis.QueryInterface(Ci.nsILineInputStream);
var cis = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
cis.init(fis,"UTF-8", 0, 0x0000);
var lis = cis.QueryInterface(Ci.nsIUnicharLineInputStream);
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
// Read the backup file
var line = {}, hasmore;
var cnt = 0;
db.beginTransactionAs(db.TRANSACTION_DEFERRED);
do {
hasmore = lis.readLine(line);
obj = JSON.decode(line.value)
stmt = db.createStatement("INSERT INTO moz_hosts VALUES ('"+obj.id+"','"+obj.host+"','"+obj.type+"','"+obj.permission+"')");
stmt.execute();
cnt++;
} while(hasmore);
db.commitTransaction();
febeAlert(febeMsg[119]);
}else{
febeAlert(febeMsg[46]);
}
return true;
}//febeRestorePermissions()
function febeRestoreProfile(){
if(!febeInitDir()){return false;}
febePathName = "";
var mask = "profileFx3{*}.fbu";
if(febePlatform == 3) mask = "*.fbu"; // Bug 444423
if(!febePickFile(mask,90)){return true};
var check1 = febePrName.indexOf("profileFx3{");
var check2 = febePrName.length - febePrName.lastIndexOf("}.fbu");
if(check1 != 0 || check2 != 5){
var tmp = "<style>color: purple; font-weight: bold; font-size: 12px;</style>"+febeMsg[103].replace("%FILE%","'"+febePrName+"'")+"\n";
tmp += "<style>color: red; font-weight: bold; font-size: 14px;</style>"+febeMsg[46];
febeAlert(tmp);
return false;
}//if
var prefName = "extensions.febe.selectedRestoreProfile";
febePrefs.setCharPref(prefName,febePathName);
var prefName = "extensions.febe.selectedRestoreProfileName";
febePrefs.setCharPref(prefName,febePrName);
// Open restore profile window
febeWin = window.openDialog("chrome://febe/content/febeProfile.xul", "FEBE", "chrome,modal,dialog=yes,alwaysRaised,centerscreen,resizable");
return true;
}//febeRestoreProfile()
function febeProfileWindowInit(){
if(!febeInitDir()){return false;}
febeWin = this.window.document;
febeProfList = [];
febeGetProfileList(febeProfList);
febeWin.getElementById("febeCurrentProfileText").value = febeProfName ;
var prefName = "extensions.febe.selectedRestoreProfile";
var febePathName = febePrefs.getCharPref(prefName); // Full path to backed up profile
var prefName = "extensions.febe.selectedRestoreProfileName";
var febePrName = febePrefs.getCharPref(prefName);
febeWin.getElementById("febeSelectedProfileText").value = febePrName;
for(var i = 0; i < febeProfList.length; i++){
var item = febeWin.getElementById("febeProfileList")
.insertItemAt ( i, febeProfList[i].Name , febeProfList[i].Path)
if(item.label == febeProfName ){item.disabled = true;}
}//for
// If there is only one profile, display help message
if(febeProfList.length == 1){
var d = document.getElementById("febeRestoreID").value;
febeHelp('99',d);
return false;
}//if
return true;
}//febeProfileWindowInit()
function febeProfileSelected(pIndex){
febeWin = this.window.document;
if(!febeWin.getElementById("febeProfileList").selectedItem){ // Profile selected?
febeAlert(febeMsg[48]);
return false;
}//if
var item = febeWin.getElementById("febeProfileList").selectedItem.label;
if(item == febeProfName ){
febeAlert(febeMsg[6]);
return false;
}//if
febeWin.getElementById("febeDestinationProfileText").value = item;
var pIndex = febeWin.getElementById("febeProfileList").selectedIndex;
return true;
}//febeProfileSelected()
function febeGetProfileList(febeProfList){
// Create pointer to Firefox root directory (where the profile directories reside)
var files = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("ProfD", Ci.nsIFile);// Was "DefProfRt"
var parentDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
parentDir.initWithPath(files.parent.path);
var entries = parentDir.directoryEntries;
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsILocalFile);
if(!entry.isDirectory()){continue;}
var p = new febeProfileObj;
var x = entry.leafName;
var P = x.indexOf(".");
p.Name = x.substring(P+1);
p.Path = entry.path;
febeProfList.push(p);
}//while
return true;
}//febeGetProfileList()
function febeStartProfileRestore(){
if(!febeInitDir()){return false;}
febeWin = this.window.document;
if(!febeProfileSelected()){return false};
var progressbox = febeWin.getElementById("febeProfileRestoreBox");
progressbox.hidden = false;
var pIndex = febeWin.getElementById("febeProfileList").selectedIndex;
var prefName = "extensions.febe.selectedRestoreProfile";
febePathName = febePrefs.getCharPref(prefName); // Full path to backed up profile
febeGetBuDate(febePathName);
if(febeConfirmRestore(75,febeBUdate)){
if(!febeInitDir()){return false;}
// Remove contents of destination profile
var destProfile = febeProfList[pIndex].Path;
pDestDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
pDestDir.initWithPath(destProfile);
var entries = pDestDir.directoryEntries;
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsILocalFile);
entry.remove(true);
}//while
var zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
zipFile.initWithPath(febePathName);
var sourceDir = zipFile.parent.path;
var destDir = destProfile;
var zipName = zipFile.leafName
var OK = new Boolean(true);
OK = febeUnzip(sourceDir,destDir,zipName);
if(OK){
febeChmod(destDir);
febeAlert(febeMsg[91]);
}else{
febeAlert(febeMsg[46]);
}//if
}else{
febeAlert(febeMsg[46]);
}//if
return true;
}//febeStartProfileRestore()
function febeRestoreUDBU(index){
var udbuLabel = febeUDBuList[index].Label;
var udbuDescription = febeUDBuList[index].Description;
var udbuType = parseInt(febeUDBuList[index].Type);
var udbuPath = febeUDBuList[index].Path;
febePathName = ""
if(!febeInitDir()){return false;}
var fMask = udbuLabel.replace(/ /g,"?")+"*";
if(udbuType == 1){fMask = udbuLabel.replace(/ /g,"?")+"*.fbu";}
if(!febePickFile(fMask,161)){return false;};
febeGetBuDate(febePathName);
febeSetMsgs();
febeMsg[163] = febeMsg[163].replace(/%fname%/,udbuDescription);
febeMsg[164] = febeMsg[164].replace(/%fname%/,udbuDescription);
if(udbuType == 0){
// File restore is a straight copy
if(febeConfirmRestore(163,febeBUdate)){
febeCopyFile(febePathName,febeParent(udbuPath),febeLeafname(udbuPath));
febeAlert(febeMsg[164]);
}else{
febeAlert(febeMsg[46]);
}//if
}else{
// Restore backed up folder
if(febeConfirmRestore(163,febeBUdate)){
var zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
zipFile.initWithPath(udbuPath);
var sourceDir = febePfParent;
febeGetPrefs();
var destDir = "";
if(febePlatform == 1){destDir = udbuPath.substr(0,3)}; // e.g., "C:\\"
if(febePlatform == 2){destDir = "/";}
if(febePlatform == 3){destDir = "/";}
var zipName = febePrName;
var OK = new Boolean(true);
OK = febeUnzip(sourceDir,destDir,zipName);
//febeWin.close();
if(OK){
febeChmod(destDir);
febeAlert(febeMsg[164].replace("%fname%",udbuLabel));
}else{
febeAlert(febeMsg[46]);
}//if
}//if
}//if
return true;
}//febeRestoreUDBU()
function febeDirCopy2(sourceDir,batchFileName){
// Recursively copy individual files and sub-directories to a destination directory
// Very tricky code ... could be written better. So little time, so much to do
var tmp = "sourceDir: "+sourceDir;
tmp += "\nfebeSubRootDir: "+febeSubRootDir;
tmp += "\nfebeDestDir: "+febeDestDir.path;
var aFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
if (!aFile) return false;
aFile.initWithPath(sourceDir);
var entries = aFile.directoryEntries;
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
var src = entry.path;
var p = src.indexOf(febeSubRootDir)
if(p == -1){continue;}
if(entry.isDirectory()){
febeDirCopy2(src,batchFileName);
}else{
var parentPath = entry.parent.path;
var dest = febeDestDir.path+"\\"+parentPath.substring(p);
var re = "\\"+batchFileName+"";
;
var file = entry.leafName;
febeCopyFile(src,dest.replace(re,"\\"),file);
}//if
}//while
return true;
}//febeDirCopy2()
// ------------------ End of Restore Functions ------------
//alert("febe.js loaded");